//
//  FormView.swift
//  SwiftUI-CTao
//
//  Created by 涛 on 2019/9/17.
//  Copyright © 2019 涛. All rights reserved.
//

import SwiftUI

struct FormView: View {
    
    @State private var enableLogging: Bool = false
    @State private var selectColor = 0
    @State private var colors: [String] = ["Red", "Yellow", "Blue", "White", "Black"]
    @State private var selectGrade = 0
    @State private var grades: [String] = ["一年级", "二年级", "三年级", "四年级", "五年级", "六年级"]
    @State private var selectSex = 0
    @State private var sexs: [String] = ["boy", "girl", "secret"]
    
    @State private var showingAdvancedOptions = false
    
    var body: some View {
        /// 1.表单功能
        /// 2.常用的几种表单选择类型:SegmentedPickerStyle、DefaultPickerStyle、WheelPickerStyle
        VStack {
            
            Toggle(isOn: $showingAdvancedOptions) {
                Text("打开更多")
            }
            
            if showingAdvancedOptions {
                Toggle(isOn: $enableLogging) {
                    Text("楼上打开了")
                }
            }
            
            Form {
                Picker(selection: $selectColor, label: Text("选择你喜欢的颜色")) {
                    ForEach(0..<colors.count) {index in
                        Text(self.colors[index])
                    }
                }
                .pickerStyle(SegmentedPickerStyle())
            }
            
            Form {
                Picker(selection: $selectGrade, label: Text("选择你的年级")) {
                    ForEach(0..<grades.count) {index in
                        Text(self.grades[index])
                    }
                }
            }.pickerStyle(DefaultPickerStyle())

            Form {
                Picker(selection: $selectSex, label: Text("选择你的性别")) {
                    ForEach(0..<sexs.count) {index in
                        Text(self.sexs[index])
                    }
                }
            }.pickerStyle(WheelPickerStyle())
        }
        .padding()
    }
}

struct FormView_Previews: PreviewProvider {
    static var previews: some View {
        FormView()
    }
}
